package com.ajaxlord.confluence.plugin.json.actions;

import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.spaces.Space;
import com.atlassian.confluence.spaces.actions.SpaceAware;
import org.randombits.confluence.support.sorting.NaturalTitleComparator;

import java.util.Collections;
import java.util.List;


public class SpaceAction extends JSONActionSupport implements SpaceAware {
    private Space space;
    private PageManager pageManager;
    private List topLevelPages;

    public List getTopLevelPages() {
        if (topLevelPages == null) {
            topLevelPages = removeInvisibleContent(pageManager.getTopLevelPages(getSpace()));
            Collections.sort(topLevelPages, new NaturalTitleComparator());
        }
        return topLevelPages;
    }

    public void setSpace(Space space) {
        this.space = space;
    }

    public boolean isSpaceRequired() {
        return true;
    }

    public boolean isViewPermissionRequired() {
        return true;
    }

    public Space getSpace() {
        return space;
    }

    public void setPageManager(PageManager pageManager) {
        this.pageManager = pageManager;
    }
}
